package com.crm.system.service.impl;

import java.util.List;
import com.crm.common.utils.DateUtils;
import com.crm.common.utils.ShiroUtils;
import com.crm.common.utils.uuid.UUID;
import com.crm.system.domain.BiePatient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.crm.system.mapper.BieInquiryMapper;
import com.crm.system.domain.BieInquiry;
import com.crm.system.service.IBieInquiryService;
import com.crm.common.core.text.Convert;

/**
 * 问诊记录Service业务层处理
 * 
 * @author crm
 * @date 2021-05-10
 */
@Service
public class BieInquiryServiceImpl implements IBieInquiryService 
{
    @Autowired
    private BieInquiryMapper bieInquiryMapper;

    @Autowired
    private BiePatientServiceImpl biePatientService;

    /**
     * 查询问诊记录
     * 
     * @param inquiryId 问诊记录ID
     * @return 问诊记录
     */
    @Override
    public BieInquiry selectBieInquiryById(String inquiryId)
    {
        return bieInquiryMapper.selectBieInquiryById(inquiryId);
    }

    /**
     * 查询问诊记录列表
     * 
     * @param bieInquiry 问诊记录
     * @return 问诊记录
     */
    @Override
    public List<BieInquiry> selectBieInquiryList(BieInquiry bieInquiry)
    {
        return bieInquiryMapper.selectBieInquiryList(bieInquiry);
    }

    /**
     * 新增问诊记录
     * 
     * @param bieInquiry 问诊记录
     * @return 结果
     */
    @Override
    public int insertBieInquiry(BieInquiry bieInquiry)
    {
        bieInquiry.setInquiryId(UUID.randomUUID().toString());
        Long userId = ShiroUtils.getUserId();
        //查出用户患者ID
        BiePatient biePatient=new BiePatient();
        biePatient.setUserId(userId);
        List<BiePatient> biePatients = biePatientService.selectBiePatientList(biePatient);
        if(biePatients==null||biePatients.size()<1){
            return -1;
        }else{
            bieInquiry.setPatientCode(biePatients.get(0).getPatientId());
        }
        bieInquiry.setCreateTime(DateUtils.getNowDate());
        return bieInquiryMapper.insertBieInquiry(bieInquiry);
    }

    /**
     * 修改问诊记录
     * 
     * @param bieInquiry 问诊记录
     * @return 结果
     */
    @Override
    public int updateBieInquiry(BieInquiry bieInquiry)
    {
        return bieInquiryMapper.updateBieInquiry(bieInquiry);
    }

    /**
     * 删除问诊记录对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBieInquiryByIds(String ids)
    {
        return bieInquiryMapper.deleteBieInquiryByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除问诊记录信息
     * 
     * @param inquiryId 问诊记录ID
     * @return 结果
     */
    @Override
    public int deleteBieInquiryById(String inquiryId)
    {
        return bieInquiryMapper.deleteBieInquiryById(inquiryId);
    }
}
